<template>
  <UserBasicForm ref="userBasicForm" v-loading="formLoading" :form-value="userBasicDetailFormValue" :isUnEditable="true"/>
  <AuditView :form-value="auditResult" :on-submit="auditUserBasicRegister"></AuditView>
</template>


<script setup>
import UserBasicForm from './UserBasicForm.vue'
import AuditView from '../flow/AuditView.vue'
import {useRoute, useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import UserBasic from "@/api/UserBasic.js";
import {ElMessage} from "element-plus";

const route = useRoute()
const router = useRouter()
const userBasicDetailFormValue = ref({"userAttendanceInfo":{}, "userEducationVOList":[], "userFamilyMemberVOList":[]});
const formLoading = ref(false);


const userId = ref();

const auditResult = ref({"dealResult":200, "rejectReason":''});

onMounted(() => {
  userId.value = route.query.userId
  const body = ref({
    id: route.query.userId,
  })
  getUserBasicDetail(body.value)
});

const getUserBasicDetail = (data) => {
  formLoading.value = true
  UserBasic.getUserBasicDetail(data)
      .then(res => {
        userBasicDetailFormValue.value = res.data
        if (!res.data.userEducationVOList) {
          userBasicDetailFormValue.value.userEducationVOList=[]
        }
        if (!res.data.userFamilyMemberVOList) {
          userBasicDetailFormValue.value.userFamilyMemberVOList=[]
        }
        formLoading.value = false
      })
      .catch(error => {
        formLoading.value = false
      })
};

const auditUserBasicRegister = () => {
  auditResult.value.userId = userId.value
  UserBasic.auditUserBasicRegister(auditResult.value)
      .then(res => {
        formLoading.value = false
        ElMessage.success('更新成功')
        router.back()
      })
      .catch(error => {
        formLoading.value = false
      })
}

const goBack = () => {
  // router.push('/salaryList')
  router.back()
}

</script>

<style scoped>

</style>